package ee.ttu.repository;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.stereotype.Repository;

/**
 * 
 * @author Elion Sõber
 *
 */
@Repository
public class KasutajakontoDaoImpl implements KasutajakontoDao {

	@PersistenceContext
	private EntityManager entityManager;

	@Override
	public boolean authenticate(String username, String password) {

		
		if(username == null || password == null){
			return false;
		}
		
		Query authQuery = entityManager.createNativeQuery("select authenticate(?1, ?2)");  

		authQuery.setParameter(1,username);
		authQuery.setParameter(2,password);

		boolean result = (Boolean) authQuery.getSingleResult();

		return result;
	}

}
